const approval = {
  state: {
    currentStep: 0,
    basicInfo: {},
    formDesign: [],
    processDesign: [],
    moreSetting: {},
    detail: {}, // 接口返回的detail信息
    submitLoading: false, // 提交按钮loading
  },
  mutations: {
    SET_CURRENT_STEP: (state, step) => {
      state.currentStep = step;
    },
    SET_BASIC_INFO: (state, info) => {
      state.basicInfo = { ...state.basicInfo, ...info };
    },
    SET_FORM_DESIGN: (state, data) => {
      state.formDesign = data;
    },
    SET_PROCESS_DESIGN: (state, data) => {
      state.processDesign = data;
    },
    SET_MORE_SETTING: (state, info) => {
      state.moreSetting = { ...state.moreSetting, ...info };
    },
    SET_DETAIL: (state, detail) => {
      state.detail = detail;
    },
    SET_SUBMIT_LOADING: (state) => {
      state.submitLoading = !state.submitLoading;
    },
  },
  actions: {
    SetCurrentStep: ({ commit }, step) => {
      commit("SET_CURRENT_STEP", step);
    },
    SetBasicInfo: ({ commit }, info) => {
      return new Promise((resolve) => {
        commit("SET_BASIC_INFO", info);
        resolve();
      });
    },
    SetFormDesign: ({ commit }, data) => {
      return new Promise((resolve) => {
        commit("SET_FORM_DESIGN", data);
        resolve();
      });
    },
    SetProcessDesign: ({ commit }, data) => {
      return new Promise((resolve) => {
        commit("SET_PROCESS_DESIGN", data);
        resolve();
      });
    },
    SetMoreSetting: ({ commit }, data) => {
      return new Promise((resolve) => {
        commit("SET_MORE_SETTING", data);
        resolve();
      });
    },
    SetDetail: ({ commit }, detail) => {
      commit("SET_DETAIL", detail);
    },
    SetSubmitLoading: ({ commit }) => {
      return new Promise((resolve) => {
        commit("SET_SUBMIT_LOADING");
        resolve();
      });
    },
  },
};

export default approval;
